<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\JxtArticle;
use App\Models\JxtBanner;

class ArticleController extends Controller
{
    public function getArticleByCategoryId($category_id): \Illuminate\Http\JsonResponse
    {
        $page_size = request('page_size', 10);
        $article = JxtArticle::where(['category_id' => $category_id, 'status' => JxtArticle::STATUS_SHOW])
            ->orderBy('id', 'desc')
            ->paginate($page_size);

        return response()->json([
            'message' => 'success',
            'code' => 0,
            'status_code' => 200,
            'data' => $article
        ]);
    }

    public function getArticle($id): \Illuminate\Http\JsonResponse
    {
        $article = JxtArticle::find($id);

        return response()->json([
            'message' => 'success',
            'code' => 0,
            'status_code' => 200,
            'data' => $article
        ]);
    }
}
